﻿

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace MyMovieSystem
{
    /// <summary>
    /// 角色管理类
    /// </summary>
    class RoleManage
    {
        /// <summary>
        /// 存储角色
        /// </summary>
        public static Dictionary<string, Role> dirRole = new Dictionary<string, Role>();

        /// <summary>
        /// 用户类对象
        /// 用于判断是否登录
        /// </summary>
        public static User user;
        /// <summary>
        /// 判断是否是管理员登录
        /// </summary>
        public static Admin admin;

        ///<summary>
        /// 初始化角色
        /// </summary>
        public static  void InitialRole()
        {
            //创建文件流
            FileStream fs = new FileStream("data//role.bin", FileMode.Open);
            //创建序列化文本类
            BinaryFormatter bf = new BinaryFormatter();
            RoleManage.dirRole = (Dictionary<string, Role>)bf.Deserialize(fs);
            fs.Close();
        }

        /// <summary>
        /// 序列化角色
        /// </summary>
        public static void SerializeRole()
        {
            //创建文件流
            FileStream fs = new FileStream("data//role.bin", FileMode.Create);
            //创建序列化文本类
            BinaryFormatter bf = new BinaryFormatter();
            //序列化
            bf.Serialize(fs, RoleManage.dirRole);
            fs.Close();
        }
    }
}
